    <template>
  <!-- 添加或修改菜单对话框 -->
  <el-dialog title="修改密码" :visible.sync="open" width="400px" append-to-body>
    <el-form ref="formData" :model="formData" :rules="rules" label-width="80px">
      <el-form-item label="用户名" prop="loginName">
        <el-input v-model="formData.loginName" size="small" disabled />
      </el-form-item>
      <el-form-item label="新密码" prop="password">
        <el-input
          type="password"
          v-model="formData.password"
          placeholder="新密码"
          size="small"
          autocomplete="off"
        />
      </el-form-item>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button
        type="primary"
        @click="submitForm('formData')"
        :disabled="loading"
        :icon="loading?'el-icon-loading':'el-icon-circle-plus-outline'"
        size="mini"
      >确 定</el-button>
      <el-button @click="open = false" size="mini">取 消</el-button>
    </div>
  </el-dialog>
</template>
<script>
import { resetPwd } from "@/api/system";
const ERR_OK = 200;
export default {
  data() {
    return {
      open: false,
      formData: {},
      rules: {
        password: [
          {
            required: true,
            message: "请输入密码",
            trigger: "blur",
          },
          { min: 6, max: 20, message: "密码 6 到 20 位数", trigger: "blur" },
        ],
      },
      loading: false,
    };
  },
  methods: {
    edit(row) {
      this.open = true;
      this.formData = {
        loginName: row.loginName,
        password: "",
        userId: row.userId,
      };
    },
    submitForm(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          this.loading = true;
          resetPwd(this.formData).then((res) => {
            this.loading = false;
            if (res.data.code === ERR_OK) {
              this.$message.success(res.data.msg);
              this.open = false;
            } else {
              this.$message.error(res.data.msg);
            }
          });
        } else {
          return false;
        }
      });
    },
  },
};
</script>